#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    int num = 0, PrevNum = 0;
    for (int i = 1; i < N; i++)
    {
        if (s[i - 1] == 'a')
        {
            if (num == 0)
                num++;
            if (s[i] == 'h')
                num++;
            else
            {
                PrevNum = max(num, PrevNum);
                num = 0;
            }
        }
        if (s[i - 1] == 'h')
        {
            if (num == 0)
                num++;
            if (s[i] == 'a')
                num++;
            else
            {
                PrevNum = max(num, PrevNum);
                num = 0;
            }
        }
        if (i == N - 1)
        {
            PrevNum = max(num, PrevNum);
        }
    }
    cout << PrevNum;
}
